package com.zhangst.bbs.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhangst.bbs.dao.BaseDaoI;
import com.zhangst.bbs.domain.Commit;
import com.zhangst.bbs.domain.Content;
import com.zhangst.bbs.page.DataList;
import com.zhangst.bbs.service.CommitServiceI;

@Service("commitService")
public class CommitServiceImpl implements CommitServiceI{

	BaseDaoI<Commit> commitDao;
	
	
	
	public BaseDaoI<Commit> getCommitDao() {
		return commitDao;
	}
	
	@Autowired
	public void setCommitDao(BaseDaoI<Commit> commitDao) {
		this.commitDao = commitDao;
	}

	@Override
	public void add(Commit commit) {
		commitDao.save(commit);
		
	}

	@Override
	public void edit(Commit commit) {
		commitDao.update(commit);
	}

	@Override
	public void del(Commit commit) {
		commitDao.delete(commit);
	}

	@Override
	public DataList getCommits(int content_id, int page, int rows) {
		Content content = new Content();
		content.setId(content_id);
		DataList list = new DataList();
		list.setPage(page);
		list.setNum(rows);;
		String hql="from Commit commit where commit.content =:content";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("content", content);
		Long total = commitDao.count("select count(*) from Commit commit where commit.content =:content",params);
		list.setTotal(total);
		list.setRows(commitDao.find(hql, params, page, rows));
		return list;
	}

}
